package com.ruoyi.gen;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class Gen {

    private static final String CODE_PATH = "D:\\yjx\\gen\\gens\\src\\main\\java";
    private static final String XML_PATH = "D:\\yjx\\gen\\gens\\src\\main\\resources\\xml";
    public static void main(String[] args) {
        FastAutoGenerator.create("jdbc:mysql://1.15.87.53:3306/rycrm-tenant-1", "root", "1Qaz2wsx")
                .globalConfig(builder -> {
                    builder.author("jx") // 设置作者
                            .enableSwagger() // 开启 swagger
//                            .outputDir("D:\\yjx\\gen\\code"); // 指定输出目录
                            .outputDir(CODE_PATH)
                            .disableOpenDir(); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.ruoyi") // 设置父包名
                            .moduleName("production") // 设置父包模块名
//                            .moduleName("basic") // 设置父包模块名
                            .entity("domain")
                            .pathInfo(Collections.singletonMap(OutputFile.xml, XML_PATH)); // 设置mapperXml生成路径
                })
                .injectionConfig(builder -> {
                    // 自定义参数
                    Map<String, Object> customMap = new HashMap<>();
                    customMap.put("export", true);
                    builder.customMap(customMap) // 注入自定义参数
                            .fileOverride() // 自定义文件覆盖
                            .build();

                })
                .strategyConfig(builder -> {
                    builder
                            .addInclude(
                                     "production_salary_settlement"
                                    ,
                                    "production_salary_employee_detail"
                                    ,
                                    "production_salary_work_record"
//                                    ,
//                                    "basic_crop_class",
//                                    "basic_crop_class_process"
//                                    "production_log_env_weather,"
//                                            +
//                                    "production_log_env_seed_zone," +
//                                            "production_log_env_indoor," +
//                                            "production_log_irrigation," +
//                                            "production_log_energy," +
//                                            "production_log_gardening,"
//                                                    +
//                                            "production_log_pests_diseases"
                            ) // 设置需要生成的表名
                            .entityBuilder()
                            .disableSerialVersionUID()
                            .enableLombok()
                            .superClass("com.ruoyi.common.core.domain.BaseEntity")  // 指定父类
//                            .addIgnoreColumns("remark")
                            .addSuperEntityColumns("create_time","update_time","create_by","update_by","remark","is_deleted")
                            .controllerBuilder()
                            .enableRestStyle()
                            .superClass("com.ruoyi.common.core.controller.BaseController")
                            .serviceBuilder()
                            .formatServiceFileName("%sService")

                    ;
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }
}
